package com.chen.web;

import com.chen.web.domain.User;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @decription
 * @atuhor:陈红卫
 * @create : 2017-06-16-15:09
 */
@RestController
public class ConsumerController {

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    private HelloService helloService;

    @RequestMapping(value = "/ribbon-consumer",method = RequestMethod.GET)
    public String HellConsumer(){
        //return restTemplate.getForEntity("http://HELLO-SERVICE/hello",String.class).getBody();

         return helloService.helloService();
    }






    @RequestMapping(value = "ribbon-consumer-inherit",method = RequestMethod.GET)
    public User HelloConsumer(){
        User u = new User();
        //创建Seeter对象只能通过此种方法来执行
        HystrixCommand.Setter setter= HystrixCommand.Setter.withGroupKey(new HystrixCommandGroupKey() {
            @Override
            public String name() {
                return "dfkgh";
            }
        });
        
        u=new UserCommand(setter,restTemplate,10L).execute();
        return  u;
    }
}
